package com.lintesis.lintesisview.common.constraints;

import org.zkoss.util.resource.Labels;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Constraint;

public class EmailConstraint  implements Constraint {

	@Override
	public void validate(Component comp, Object value)
			throws WrongValueException {
		String pattern = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[_A-Za-z0-9-]+)";

		String stringValue=(String)value;
		if (value != null && stringValue.length()>0 && !stringValue.matches(pattern)) {
			
			throw new WrongValueException(comp,Labels.getLabel("EmailNotValid"));
		}
	}

}